/**
 * Created with JetBrains PhpStorm.
 * User: jiangshuguang
 * Date: 14-9-28
 * Time: 下午9:16
 * To change this template use File | Settings | File Templates.
 */

(function(){
    var util = require("wap_common:widget/ui/libs/util.js").util,
        ShareTip = require("wap_common:widget/ui/sharetip/sharetip.js").ShareTip,
        $page = $(".main-myassets"),
        share,shareTip;

    //分享提高额度
    P.share.data({
        onSendFriends:function(res){
            if(res.err_msg == "share_timeline:ok"){
                $.get("/wap/sharestatistic",res,function(ret,status){});
            }
        }
    });

   //分享的提示
    shareTip = new ShareTip({
        content:'' +
            '<div style="text-align: left">每周（每隔7天）有一次分享提高额度的机会，共有三次提高额度的机会</div>' +
            '<div>注：必须分享到朋友圈哦</div>' +
            '<div></div>' +
            ''
    });

    function createPie(data){
        var ctx = document.getElementById("chart-area").getContext("2d");
        new Chart(ctx).Doughnut(data,{
            segmentStrokeWidth:1,
            segmentStrokeColor:"#888"
        });
    }

    $.getJSON('/user/userfundsummary',function(ret,status) {
        if(status == "success" && ret.error_no == 0){
            var data = ret.data;
            $page.find(".yesterday-profit").text("￥"+util.formatAmount(data.yesterday_profit,4));
            $page.find(".total-profit").text("￥"+util.formatAmount(data.total_profit,4));
            $page.find(".total-assets").text("￥"+util.formatAmount(data.total,4));
            $page.find(".bought-amount").text("￥"+util.formatAmount(data.bought_amount,4));
            $page.find(".type .queue-assets").text("￥"+util.formatAmount(data.waiting_amount,4));
            $page.find(".type .profit").text("￥"+util.formatAmount(data.profit,4));
            $page.find(".type .frozen-assets").text("￥"+util.formatAmount(data.freeze,4));
            if(data.bought_amount>0 || data.total_profit>0 || data.waiting_amount){
                createPie([
                    {
                        value: util.formatFloat(data.total_profit,2),
                        color: "#ffe380",
                        highlight: "#ffe300",
                        label: "收益资金"
                    },
                    {
                        value: util.formatFloat(data.bought_amount+data.waiting_amount,2),
                        color: "#333367",
                        highlight: "#333300",
                        label: "已购买资产"
                    }
                ]);
            }else{
                $(".pie-container").hide();
            }
        }
    });

    $page.find(".btn-share").click(function(){
        shareTip.showShare();
    });
})();